package com.example.administrator.appstpremvpdemo.wegit;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.appstpremvpdemo.R;
import com.example.administrator.appstpremvpdemo.common.Constances;
import com.example.administrator.appstpremvpdemo.model.entity.ValueBean;

/**
 * Created by Administrator on 2017/12/5.
 */

public class DownLoadButton extends RelativeLayout {

    private ProgressBar mProgressbar;
    private TextView mTextview;
    private int mProgress;
    private View mBackground;

    public DownLoadButton(Context context) {
        super(context);
    }

    public DownLoadButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DownLoadButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        View inflate = LayoutInflater.from(context).inflate(R.layout.downloadbutton, this, true);
        mProgressbar = ((ProgressBar) inflate.findViewById(R.id.pb));
        mTextview = ((TextView) inflate.findViewById(R.id.tv));
        mBackground = ((View) inflate.findViewById(R.id.background));
        init();
    }

    private void init() {
        mProgressbar.setProgress(0);
    }

    public int getProgress() {
        return mProgress;
    }

    public void setProgress(int progress) {
        this.mProgress = progress;
        mProgressbar.setProgress(progress);
    }

    String mString;

    public void setTextview(String str) {
        this.mString = str;
        mTextview.setText(str);
    }

    private ValueBean mAppInfoBean;

    /**
     * 根据app信息 存储的状态更新按钮状态
     *
     * @param appInfoBean
     */
    public void refreshStatus(ValueBean appInfoBean) {
        this.mAppInfoBean = appInfoBean;
        if (mProgressbar != null || mTextview != null) {
            mProgressbar.setProgress(appInfoBean.getStatusModel().getProgress());
            mTextview.setText(appInfoBean.getStatusModel().getTextmsg());
        }
    }
}
